import router from '@/router'
import fa from 'element-ui/src/locale/lang/fa'

function init () {
  var that = this
  setTimeout(function () {
    console.log('1：' + Notification.permission)
    //如果支持window.Notification 并且 许可不是拒绝状态
    if (window.Notification && Notification.permission !== 'denied') {
      //Notification.requestPermission这是一个静态方法，作用就是让浏览器出现是否允许通知的提示
      Notification.requestPermission(function (status) {
        //如果状态是同意
        if (status === 'granted') {
          return true
        } else {
          that.$notify('当前浏览器不支持弹出消息')
          return false
        }
      })
    }
  }, 1000)

}

const notification = {
  notify (title, body, icon, path) {
    init()
    var m = new Notification(title, {
      body: body, //消息体内容
      icon: icon //消息图片
    })
    //点击当前消息内容
    m.onclick = function () { //点击当前消息提示框后，跳转到当前页面
      router.push({ path: path })
      window.focus()
    },
      //点击关闭消息提示框
      m.onclose = function () {
        m.close()
      }

  }
}
export default notification
